
package kaizone.haining.chaobohui.widget;

import kaizone.haining.chaobohui.R;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ToggleButton;

public class UsersFunction extends LinearLayout implements OnClickListener, OnCheckedChangeListener {

    private LinearLayout mPanel01;

    private LinearLayout mPanel02;

    private TextView mTextView01;

    private TextView mTextView02;

    private ToggleButton mToggleButton01;

    private View mDrivesView;

    private OnClickListener mClickListener;

    private OnCheckedChangeListener mCheckedChangeListener;

    public UsersFunction(Context context) {
        super(context);
        init();
    }

    public UsersFunction(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {

    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mPanel01 = (LinearLayout) findViewById(R.id.linearlayout01);
        mPanel02 = (LinearLayout) findViewById(R.id.linearlayout02);
        mTextView01 = (TextView) findViewById(R.id.tv01);
        mTextView02 = (TextView) findViewById(R.id.tv02);
        mToggleButton01 = (ToggleButton) findViewById(R.id.togglebtn);
        mDrivesView = (View) findViewById(R.id.drives);
        mTextView01.setClickable(true);
        mTextView02.setClickable(true);
        mTextView01.setOnClickListener(this);
        mTextView02.setOnClickListener(this);
        mToggleButton01.setOnCheckedChangeListener(this);
    }

    public void setText01(String text) {
        mTextView01.setText(text);
    }

    public void setText02(String text) {
        mTextView02.setText(text);
    }

    public void setToggleTextOn(CharSequence textOn) {
        mToggleButton01.setTextOn(textOn);
    }

    public void setToggleTextOff(CharSequence textOff) {
        mToggleButton01.setTextOff(textOff);
    }

    public void setToggleButtonVisibility(int visibility) {
        mToggleButton01.setVisibility(visibility);
    }

    public void setPanel01Visibility(int visibility) {
        mPanel01.setVisibility(visibility);
        if (visibility == View.GONE) {
            mDrivesView.setVisibility(View.GONE);
        }
    }

    public void setPanel02Visibility(int visibility) {
        mPanel02.setVisibility(visibility);
        if (visibility == View.GONE) {
            mDrivesView.setVisibility(View.GONE);
        }
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (mCheckedChangeListener != null) {
            mCheckedChangeListener.onCheckedChanged(buttonView, isChecked);
        }
    }

    @Override
    public void onClick(View v) {
        if (mClickListener != null) {
            mClickListener.onClick(v);
        }
    }

    public int getTextView01Id() {
        return mTextView01.getId();
    }
    
    public View getTextView01() {
        return mTextView01;
    }

    public int getTextView02Id() {
        return mTextView02.getId();
    }
    
    public View getTextView02() {
        return mTextView02;
    }

    public void setOnClickListener(OnClickListener listener) {
        mClickListener = listener;
    }

    public void setOnCheckedChangeListener(OnCheckedChangeListener listener) {
        mCheckedChangeListener = listener;
    }

    public interface OnClickListener {
        void onClick(View v);
    }

    public interface OnCheckedChangeListener {
        void onCheckedChanged(CompoundButton buttonView, boolean isChecked);
    }

}
